package org.springblade.oa.wrappper;

import org.springblade.common.constant.CommonConstant;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.oa.entity.InvoiceImage;
import org.springblade.oa.vo.InvoiceImageVo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LK
 * @version 1.0.0
 * @Title: InvoiceImageWrapper.java
 * @Description: TODO
 * @date 2020/4/17 16:18
 */
public class InvoiceImageWrapper extends BaseEntityWrapper<InvoiceImage, InvoiceImageVo> {

	public static InvoiceImageWrapper build() {
		return new InvoiceImageWrapper();
	}

	@Override
	public InvoiceImageVo entityVO(InvoiceImage invoiceImage) {
		InvoiceImageVo invoiceImageVo = BeanUtil.copy(invoiceImage, InvoiceImageVo.class);
		String path = invoiceImage.getPath();
		invoiceImageVo.setUrl("/api/" + CommonConstant.APPLICATION_OA_NAME + "/image/" + path.substring(path.lastIndexOf("/", path.lastIndexOf("/") - 1) + 1));
		return invoiceImageVo;
	}

	/**
	 * 报销发票列表数据包装
	 *
	 * @param list
	 * @return
	 */
	public List<InvoiceImageVo> entityVOList(List<InvoiceImage> list) {
		List<InvoiceImageVo> invoiceImageVoList = new ArrayList<>();
		for (InvoiceImage invoiceImage : list) {
			invoiceImageVoList.add(entityVO(invoiceImage));
		}
		return invoiceImageVoList;
	}
}
